from flask import Flask
from flask import request

from dnn import predict_class
from dnn import get_model

import json

app = Flask(__name__)
classifier = get_model()


# @app.route('/')
# def hello_world():
#     return 'Hello World!'


@app.route('/predict/<record>', methods=['GET', 'POST'])
def predict(record):
    class_num = predict_class(record, classifier)
    result = {'class': class_num}
    result_json = json.dumps(result)
    callback = request.args.get('callback')
    callback_str = str(callback)
    if callback_str != 'None' and callback_str != '':
        return callback_str + "(" + result_json + ")"
    return result_json


if __name__ == '__main__':
    app.run(host='0.0.0.0')
    # app.run(debug=True)
